/*
 * Copyright 2011-2012 Redia A/S
 * 
 * This file is part of Redias Library App for Android.
 *
 *  Redia Library App for Android is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Redia Library App for Android is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Redia Library App for Android.  If not, see <http://www.gnu.org/licenses/>.
 */
package dk.redia.libraryapp.viewutils;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import dk.redia.lib.utils.AppApplication;
import dk.redia.libraryapp.utils.ResourceUtils;

public class ViewUtils {
	
	private static Bitmap newsItemGradientBitmap;
	private static Bitmap newsItemDefaultBitmap;
	
	public static Bitmap getNewsItemGradientBitmap() {
		if (newsItemGradientBitmap==null) {
			newsItemGradientBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);			    	
	    	Canvas gradientBmpCanvas = new Canvas(newsItemGradientBitmap);
	    	LinearGradient gradient = new LinearGradient(75, 0, 100, 0, Color.TRANSPARENT, 0x89000000, Shader.TileMode.CLAMP);		    	
	    	Paint p = new Paint();
			p.setStyle(Paint.Style.FILL);
			p.setShader(gradient);
	    	gradientBmpCanvas.drawColor(Color.TRANSPARENT);
	    	gradientBmpCanvas.drawRect(0, 0, 100, 100, p);
		}
		return newsItemGradientBitmap;
	}

	public static Bitmap getNewsItemDefaultBitmap() {
		if (newsItemDefaultBitmap==null) {
			int resourceId = ResourceUtils.getNoImageResourceId();
			BitmapDrawable bd = (BitmapDrawable)AppApplication.getAppContext().getResources().getDrawable(resourceId);
			newsItemDefaultBitmap = bd.getBitmap();
		}
		return newsItemDefaultBitmap;
	}
}
